﻿using AllInOne.Classes;
using AllInOne.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AllInOne.ViewModels
{
    public class PlateInputWinViewModel : NotifyBase
    {
        public PlateInputWinModel PlateInputWinModel { get; set; } = new PlateInputWinModel();
        public CommandBase CloseWindowCommand { get; set; }

        public CommandBase LoginCommand { get; set; }

        private string _errorMessage;
        public string ErrorMessage
        {
            get { return _errorMessage; }
            set { _errorMessage = value; this.DoNotify(); }
        }

        public PlateInputWinViewModel()
        {
            ////初始化放 上面--有6个点，就表示LoginModel.Password已经绑定上了
            //this.LoginModel = new LoginModel();
            //this.LoginModel.UserName = "杨";
            //this.LoginModel.Password = "123456";

            #region 关闭按钮
            this.CloseWindowCommand = new CommandBase();
            ////关闭按钮要怎么做
            //this.CloseWindowCommand.DoExecute = new Action<object>((o) =>
            //{
            //    (o as Window).Close();
            //});
            //this.CloseWindowCommand.DoCanExecute = new Func<object, bool>((o) =>
            //{ return true; });
            #endregion


            #region 登录按钮
            //绑定登录按钮的事件
            this.LoginCommand = new CommandBase();
            this.LoginCommand.DoExecute = new Action<object>(DoLogin);
            this.LoginCommand.DoCanExecute = new Func<object, bool>((o) =>
            { return true; });
            #endregion
        }
        /// <summary>
        /// 主要的登录逻辑在这个方法里面
        /// </summary>
        /// <param name="o"></param>
        private void DoLogin(object o)
        {
            //this.ErrorMessage = "";
            //if (string.IsNullOrEmpty(LoginModel.UserName))
            //{
            //    this.ErrorMessage = "请输入用户名字";
            //    return;
            //}
            //if (string.IsNullOrEmpty(LoginModel.Password))
            //{
            //    this.ErrorMessage = "请输入密码";
            //    return;
            //}
        }

        //回车键
        //https://www.bilibili.com/video/BV1c34y1j7Fx?p=19
        //几种方法1.button 登录里面有个 isDefault=true
        //有个问题就是必须，光标切换一下再回车才行。
        //2.或者用TextBox.InputBing <keybinding key="Enter" command="{Bing LoginWindow_Win
    }
}
